import cv2
import matplotlib.pyplot as plt
import numpy as np
from holoviews.core.traversal import hierarchical
from numba import uint8
from sympy.abc import epsilon

def cv_show(name,img):
    cv2.imshow(name,img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

img = cv2.imread('C:/Users/nic/Desktop/opencv/picture/map.jpg')
templet = cv2.imread('C:/Users/nic/Desktop/opencv/picture/templet_map.jpg')
#获取templet的width和high
w,h = templet.shape[0:2]
#methods are cv2.TM_CCOEFF,cv2.TM_CCOEFF_NORMED,cv2.TM_CCORR,cv2.TM_CCORR_NORMED,cv2.TM_SQDIFF and cv2.TM_SQDIFF_NORMED
res = cv2.matchTemplate(img,templet,cv2.TM_CCORR_NORMED)
#阈值，大于0.99的都会被标注
threshold = 0.99
loc = np.where(res>=threshold)
for pt in zip(*loc[::-1]):
    right_bottom = (pt[0]+w,pt[1]+h)
    cv2.rectangle(img,pt,right_bottom,(255,0,0),1)

cv_show('img',img)








